function! auto#correct(word)
if has('python3')
py3 << EOF
import vim
import re
import enchant

def Correct(word):
	if len(word) == 0:
		return []
	dt = enchant.Dict('en_US')
	ret = dt.suggest(word)
	if len(ret) > 0:
		ret.insert(0, word)
		return ret
	else:
		return []

result = Correct(vim.eval("a:word"))

vim.command("let ret = " + str(result))
EOF
return ret
endif
endfunction


function! auto#complete(findstart, base)
	if a:findstart
		" locate the start of the word
	    let line = getline('.')
	    let start = col('.') - 1
	    while start > 0 && line[start - 1] =~ '\a'
	      let start -= 1
	    endwhile
	    return start
	else
		" let word = getline('.')[0:col('.') - 1]
		let _result = auto#correct(a:base)
		return {'words': _result, 'refresh': 'always'}
	endif
endfunction

